<?php
	require_once('../conexion/conexion.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style>
.texto
{
	font-family:Verdana;
	font-size:9px;
}
</style>

</head>

<body>
<form name="facexen" id="facexen" method="post">
<?php
	extract($_POST);
	//datos del proveedor
	$con = new Conexion();
    $con2 = $con->conexionBD("fpproduccion");
    $sql = "select 
				ProvNombre,
				ProvFono,
				ProvDireccion,
				ProvGiro,
				ProvComuna
				
				from proveedor 
				where ProvRut='".$_GET['rut']."'";
    $res = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
	$prov = mysql_fetch_array($res);
	
	$nombre = utf8_decode($prov[0]);
	$dir = utf8_decode($prov[2]);
	$giro = utf8_decode($prov[3]);
	$comuna = utf8_decode($prov[4]);
	
	$con->cerrarBD();
?>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<tr>
  <td width="9%"><label class="texto">Fecha:</label></td>
	<td width="56%"><label class="texto"><?php echo $_GET['fecha'];?></label></td>
	<td width="14%">&nbsp;</td>
	<td width="21%">&nbsp;</td>
</tr>
<tr>
  <td><label class="texto">Se&ntilde;or:</label></td>
	<td><label class="texto"><?php echo $nombre;?></label></td>
	<td><label class="texto">Rut:</label></td>
	<td><label class="texto"><?php echo $_GET['rut'];?></label></td>
</tr>
<tr>
  <td><label class="texto">Direcci&oacute;n:</label></td>
	<td><label class="texto"><?php echo $dir;?></label></td>
	<td><label class="texto">Comuna:</label></td>
	<td><label class="texto"><?php echo $comuna;?></label></td>
</tr>
<tr>
  <td><label class="texto">Giro:</label></td>
	<td><label class="texto"><?php echo $giro;?></label></td>
	<td><label class="texto">Tel&eacute;fono:</label></td>
	<td><label class="texto"><?php echo $prov[1];?></label></td>
</tr>
<tr>
  <td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
</tr>
</table>
<div style="height:10px"></div>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<tr style="background-color:#CCCCCC">
	<td width="10%" style="text-align:center"><label class="texto">CANTIDAD</label></td>
	<td width="54%" style="text-align:center"><label class="texto">DETALLE</label></td>
	<td width="20%" style="text-align:center"><label class="texto">P. UNITARIO</label></td>
	<td width="16%" style="text-align:center"><label class="texto">TOTAL</label></td>
</tr>
<?php
	//items de la factura
	$suma = 0;
	$cont = 0;

	$vector = explode(";",$_GET['items']);
	$cant = (count($vector)-1)/4;
	
	for($i=1;$i<=$cant;$i++)
	{
			echo "<tr>";
			echo "<td style='text-align:center'><label class='texto'>".$vector[$cont]."</label></td>";
			echo "<td style='text-align:center'><label class='texto'>".$vector[$cont+1]."</label></td>";
			echo "<td style='text-align:center'><label class='texto'>".number_format($vector[$cont+2],0,',','.')."</label></td>";
			echo "<td style='text-align:center'><label class='texto'>".number_format($vector[$cont+3],0,',','.')."</label></td>";
			echo "</tr>";
			$suma += $vector[$cont+3];
			$cont += 4;
	}
	$iva = round($suma*0.19);
	$total = $iva+$suma;
?>
<tr><td colspan="4">&nbsp;</td></tr>
</table>
<div style="text-align:right; padding-right:22px;">
<table width="20%" cellpadding="4" cellspacing="0" border="0">
<tr>
	<td width="27%"><label class="texto">NETO:</label></td>
	<td width="73%"><label class="texto"><?php echo number_format($suma,0,',','.')?></label></td>
</tr>
<tr>
	<td><label class="texto">IVA:</label></td>
	<td><label class="texto"><?php echo number_format($iva,0,',','.')?></label></td>
</tr>
<tr>
	<td><label class="texto">TOTAL:</label></td>
	<td><label class="texto"><?php echo number_format($total,0,',','.')?></label></td>
</tr>
</table>
</div>
</form>
</body>
</html>
